package com.xja.controller;

import cn.hutool.json.JSON;
import com.xja.model.entity.Tongue;
import com.xja.model.vo.req.TongueDiagnosisReqVO;
import com.xja.model.vo.resp.Result;
import com.xja.service.ITongueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 * 舌诊表 前端控制器
 * </p>
 *
 * @author caijg
 * @since 2025-06-08
 */
@RestController
@RequestMapping("/user/tongue")
@RequiredArgsConstructor
@Tag(name = "舌诊模块")
@Slf4j
public class TongueController {

    private final ITongueService tongueService;

    @PostMapping("/diagnosis")
    @Operation(summary = "舌诊诊断")
    public Result<Tongue> diagnosis(@RequestBody TongueDiagnosisReqVO tongueDiagnosisReqVO) {
        log.info("舌诊诊断开始...");
        Tongue tongue = tongueService.diagnosis(tongueDiagnosisReqVO);
        return Result.success(tongue);
    }

    @Operation(summary = "查询舌诊历史记录")
    @GetMapping("/history")
    public Result<JSON> history() {
        log.info("用户舌诊历史查询...");
        JSON json = tongueService.history();
        return Result.success(json);
    }

    @Operation(summary = "删除舌诊历史记录")
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody ArrayList<String> ids) {
        log.info("删除舌诊记录：{}", ids);
        Boolean deleted = tongueService.delete(ids);
        return Result.success(deleted);
    }

    @Operation(summary = "获取舌苔特征描述")
    @GetMapping("/{id}")
    public Result<Tongue> getById(@PathVariable Integer id) {
        Tongue tongue = tongueService.getById(id);
        return Result.success(tongue);
    }
}